function snr = wide_signal_noise_ratio(fftdata,freq,nHarmonics,Fs)
%SNR 计算宽带信噪比
% fftdata: 输入的频谱数据,行为采样点，列为通道
% freq:信号频率
% nHarmonics: 谐波次数
% Fs:采样频率
signalPower = zeros(size(fftdata,2),nHarmonics);
deltaf = Fs/size(fftdata,1)/2;
for i = 1:nHarmonics
    signalPower(:,i) = fftdata(round(i*freq/deltaf)+1,:).^2';
end
sumPower = sum(fftdata(1:round(Fs/(2*deltaf)),:).^2,1)';
noisePower = sumPower - sum(signalPower,2);
snr = mean(10*log(sum(signalPower,2)./noisePower));
end

